<template>
	<view class="container">
		<uni-section title="图" type="line">
			<image :src="'http://localhost:8090'+findones.icon" style="width: 100%;height: 150px;"></image>
		</uni-section>
		<uni-section title="名称" type="line">
			<text>{{findones.name}}</text>
		</uni-section>
		<uni-section title="类别" type="line">
			<text>{{findones.type}}</text>
		</uni-section>
		<uni-section title="价格" type="line">
			<text>{{findones.price}}</text>
		</uni-section>
		<uni-section title="描述" type="line">
			<text>{{findones.description}}</text>
		</uni-section>
		<view class="" style="display: flex;position: fixed;bottom: 5px;">
		<input v-model="comments" placeholder="请输入评论内容" style="width: 283px;height: 35px;border: 1px solid #ccc;background-color: #fff;" />
		<button @click="add" type="default" style="width: 90px;height: 37px;border:1px solid #ccc;line-height: 37px;">发表</button>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				findones:{
					
				},
				comments:""
			}
		},
		methods: {
			add(){
				if(!this.comments){
					uni.showToast({
						title: '评论内容不能为空',
						icon: 'none'
					});
					return false
				}else{
				var id = this.findones.id
				uni.request({
					url: 'http://localhost:8090/foodapp/comment/addone',
					method: 'POST',
					data: {
						foodid:id,
						userid:1,
						comment:this.comments,
						postdate:new Date()
					},
					success: res => {
						if (res.data.success) {
							uni.showToast({
								title: '评论成功',
								icon: 'none'
							});
							this.comments=''
						} else {
							uni.showToast({
								title: '失败',
								icon: 'none'
							});
						}
					},
					fail: () => {
						uni.showToast({
							title: '失败',
							icon: 'none'
						});
					},
					complete: () => {}
				});
			}
			}
		},
		// onLoad: () => {
		// 	uni.onTabBarMidButtonTap(function(e){
		// 		console.log(e)
				
		// 	})
			
		// }
		onLoad(id) {
			uni.request({
				url: 'http://localhost:8090/foodapp/food/findone',
				method: 'POST',
				data: {"id":id.id},
				success: res => {
					if (res.data.success) {
						this.findones = res.data.data
						uni.showToast({
							title: '成功',
							icon: 'none'
						});
					} else {
						uni.showToast({
							title: '失败',
							icon: 'none'
						});
					}
				},
				fail: () => {
					uni.showToast({
						title: '失败',
						icon: 'none'
					});
				},
				complete: () => {}
			});
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
